﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     <title>My fisrt ArcGis Map</title>
         <link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
    <script src="https://js.arcgis.com/3.16/"></script>
    
    
     <script type="text/javascript">
         dojo.require("esri.map");
         var map;
         function init() {
        	 map = new esri.Map("arcgisDiv");
         	var tiled= new esri.layers.ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer");
            var dynamic=new esri.layers.ArcGISDynamicMapServiceLayer("https://yuanc.esrichina.com/arcgis/rest/services/hx/MapServer");
           // myMap = new esri.Map(dojo.byId("map2"));
           map.addLayer(dynamic);
           //map.addLayer(tiled);
            map.on("load",mapOnload);
         } 
         
      	function mapOnload()
     	{
     		map.on("click",mapOnClick);
     	}
      	
     	function mapOnClick(event)
     	{
     		try
     		{
     		var point =new esri.geometry.Point(event.mapPoint.x,event.mapPoint.y);
     		alert(JSON.stringify(point));
     		var symbol= new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10,  
     			                     new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,  
     						         new esri.Color([255,0,0]), 1),  
     					             new esri.Color([0,255,0,0.25]));  
     		var graphic = new esri.Graphic(point,symbol);
     		var gpServiceUrl = "https://yuanc.esrichina.com/arcgis/rest/services/BurstAnalysis/GPServer/Burst";
     	    var gp = new Geoprocessor(gpServiceUrl); 
     	    map.graphics.add(graphic);
     	    var features = [];  
                var g1 = new esri.Graphic(point,symbol);
                features.push(g1);
                var featureset = new esri.tasks.FeatureSet();  
                featureset.features = features;
     	    var gp = new esri.tasks.Geoprocessor(gpServiceUrl);
     	    var burstfeatureset={
     	    		 "displayFieldName": "",
     	    		 "geometryType": "esriGeometryPoint",
     	    		 "spatialReference": {
     	    		  "wkid": 4326,
     	    		  "latestWkid": 4326
     	    		 },
     	    		 "fields": [{
     	    		  "name": "OBJECTID",
     	    		  "type": "esriFieldTypeOID",
     	    		  "alias": "OBJECTID"
     	    		 }],
     	    		 "features": [{"geometry":{"point":[[[event.mapPoint.x,event.mapPoint.y]]]}}],
     	    		 "exceededTransferLimit": false
     	    		};
     	    var params={
     	    		Burst:burstfeatureset
     	    };
     		gp.submitJob(params, gpJobComplete, gpJobStatus, gpJobFailed);
     		}catch(error)
     		{
     			alert(error.message);
     		}
     	}
     	
     	
     	function jobResult(result) {  
     	    var jobId = result.jobId;  
     		    var status = result.jobStatus;  
     		    if(status === esri.tasks.JobInfo.STATUS_SUCCEEDED) {  
     		        //成功之后，将其中的结果取出来，当然这也是参数名字。  
     		        //在模型中，想要取出中间结果，需要设置为模型参数  
     		        //gp.getResultData(jobId, "output", addResults);  
     		    }
       }  
     	
     	
        function findHotspot() {
     		//map.on("click",mapOnClick);
          /*   query = new Query();    
            featureLayer = new FeatureLayer("http://192.168.0.248:6080/arcgis/rest/services/guanx/guanx/MapServer/1");    
            query.returnGeometry = true;    
            query.outFields = ["*"];    
            query.where = "1=1";    
            featureLayer.queryFeatures(query, function (fs) {    
                featureSet = fs;    
               var gp = new Geoprocessor(gpServiceUrl);    
               var vsDistance = new LinearUnit();    
               vsDistance.distance = 50000;    
              //该单位根据GP发布的单位进行选择    
               vsDistance.units = "esriFeet";    
               //设置GP参数    
               var params = {    
                  SDE_subway: featureSet,    
                    Expression: buildDefinitionQuery(),    
                    Distance__value_or_field_: vsDistance    

              };    
               //cleanup any results from previous runs    
               cleanup();    
              gp.submitJob(params, gpJobComplete, gpJobStatus, gpJobFailed);    
            }); */
       }
     	
        //GP完成之后加载结果图层    
        function gpJobComplete(jobinfo) {   
        	
        	  alert(jobinfo.jobId);
    /*          //construct the result map service url using the id from jobinfo we'll add a new layer to the map    
             var mapurl = mapserviceurl + "/" + jobinfo.jobId;    
             var hotspotLayer = new ArcGISDynamicMapServiceLayer(mapurl, {    
                "id": "bufferlayer"    
             });    

            //add the hotspot layer to the map    
            map.addLayers([hotspotLayer]); */
            
            
        }    
        //获得GP运行状态    
        function gpJobStatus(jobinfo) {    
            //domUtils.show(dom.byId('status'));    
             var jobstatus = '';    
            switch (jobinfo.jobStatus) {    
                case 'esriJobSubmitted':    
                     jobstatus = 'Submitted...';    
                   break;    
               case 'esriJobExecuting':    
                     jobstatus = 'Executing...';    
                    break;    
                 case 'esriJobFailed':    
                    jobstatus = 'Failed...';    
                     break;    
                case 'esriJobSucceeded':  
                	jobstatus = 'Succeeded...'
                     //domUtils.hide(dom.byId('status'));    
                     break;    
             }    
             //dom.byId('status').innerHTML = jobstatus;
             alert(jobstatus);
         }    
         //获得GP失败信息    
        function gpJobFailed(error) {   
        	//alert("gp:error"+error);
            //dom.byId('status').innerHTML = error;    
            //domUtils.hide(dom.byId('status'));    
        }
     	
     	
     	
         dojo.addOnLoad(init);
     </script>
  </head>
  <body class="tundra">
     <div id="arcgisDiv" style="width:900px; height:600px; border:1px solid #000;"></div>
  </body>
</html>